package sd.socket.udp.client;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

import sd.socket.interfaces.IService;

public class ServiceClientProxy implements IService{
	private String address = null;
	private int port;
	
	public ServiceClientProxy(String address, int port) {
		this.port = port;
		this.address = address;
	}

	@Override
	public String doSomeThing(String string) {
		String s = null;
		ProcessBuilder pb = new ProcessBuilder();
		pb.directory(new File("/home/v/sd/socket/socket_4/"));
		pb.command(new String[] {"./client.o", string});
		pb.redirectErrorStream(true);
		
		Process p;
		
		try {
			p = pb.start();
			
			
			BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

			BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

        	// read the output from the command
       	    while ((s = stdInput.readLine()) != null) {
         		System.out.println(s);
            }
            
        	// read any errors from the attempted command
    		while ((s = stdError.readLine()) != null) {
        		System.out.println(s);
    		}

    		stdInput.close();
    		stdError.close();
    		
    		p.destroy();
    		
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return null;
	}
	

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}
	
	
}
